require(['config'],()=>{
    require(['header'],()=>{
        require(['swiper','footer','floater','pAjax'],(Swiper)=>{
            class Index{
                constructor(){
                    this.div=document.querySelectorAll('.swiper-slide')
                    this.poster=document.querySelector('#poster')
                    this.banner()
                }
                banner (){
                    new Swiper('.swiper-container', {
                        pagination: '.swiper-pagination',
                        nextButton: '.swiper-button-next',
                        prevButton: '.swiper-button-prev',
                        slidesPerView: 3,
                        centeredSlides: true,
                        paginationClickable: true,
                        spaceBetween: 30,
                    });
                    this.request()
                }
                request() {
                    pAjax({
                            url: '/api/goods.json'
                        })
                        .then(data => {
                            let res = JSON.parse(data)
                            res = res.slice(0, 10)
                            this.render(res)
                        })
                }
                render(data) {
                    for(let i=0;i<data.length;i++){
                        this.div[i].innerHTML +=`
                            <div data-id="${data[i].goods_id}">
                                <img src='${data[i].img_big_logo}'>
                                <p>${data[i].title}</p>
                            </div>
                        `
                        this.div[i].onclick=()=>{
                            window.open(`/html/details.html?id=${data[i].goods_id}`)
                        }
                    }
                    this.poster.onclick=()=>{
                        window.open("/html/wares.html")
                    }
                    this.totalNum()
                }
                totalNum(){
                    let list = JSON.parse(localStorage.getItem('cart')) || []
                    let num = 0
                    list.forEach(item=>{
                        num += item.cart_number
                    })
                }
            }
            new Index()
        })
    })
})